<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改边缘人广告位')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-advertising-edit" th:object="${ppAdvertising}">
            <input name="advertisingId" th:field="*{advertisingId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input id="giftUrl" name="files"  class="form-control" type="file" onchange="gift()">
                    <input id="url" name="advertisingUrl" class="form-control aa" type="text" style="display: none">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="advertisingTime" th:value="${#dates.format(ppAdvertising.advertisingTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "app/advertising";
        $("#form-advertising-edit").validate({
            focusCleanup: true
        });

        var img = [];
        //单独上传图片
        $(document).ready(function () {
            // console.log($('#form-village-add').serialize())
            $("#giftUrl").fileinput({
                showUpload: false,
                //设置语言
                language: 'zh',
                //异步上传
                uploadAsync: true,
                dropZoneEnabled: true,
                uploadUrl: ctx + "qiniu/uploadFiles",
                maxFileCount: 1,
                resizeImage: false,
                showCaption: false,
                showPreview: true,
                initialPreviewAsData:true,
                //预览项设置
                layoutTemplates:{
                    //去除详细预览
                    actionZoom:'',
                },
                initialPreview: [
                    '[[${ppAdvertising.advertisingUrl}]]'
                ],
                allowedFileTypes: ['image'],
                browseClass: "btn btn-primary btn-lg",
                //自动替换当前文件
                autoReplace:true,
            }).on("filebatchselected", function (event, files) {
                $(this).fileinput("upload");
            }).on("fileuploaded", function (event, data) {
                if (data.response) {
                    img[img.length] = data.response.data[0].url;
                    $(".aa").val(data.response.data[0].url);
                }
            });
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-advertising-edit').serialize());
            }
        }

        $("input[name='advertisingTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>